package com.koi.generator.utils;

import java.util.HashMap;
import java.util.Map;

/**
 * @author ･ᴗ･
 * @description [MySQLToJavaTypeConverter-MySQL 数据类型完整映射表工具类]
 */
public class MySQLToJavaTypeUtil {
    private static final Map<String, String> typeMap = new HashMap<>();

    static {
        typeMap.put("varchar", "String");
        typeMap.put("char", "String");
        typeMap.put("text", "String");
        typeMap.put("longtext", "String");
        typeMap.put("tinytext", "String");
        typeMap.put("mediumtext", "String");

        typeMap.put("int", "Integer");
        typeMap.put("integer", "Integer");
        typeMap.put("smallint", "Integer");
        typeMap.put("bigint", "Long");

        typeMap.put("float", "String");
        typeMap.put("double", "String");
        typeMap.put("decimal", "String");

        typeMap.put("date", "Date");
        typeMap.put("datetime", "Date");
        typeMap.put("timestamp", "Date");

        typeMap.put("tinyblob", "Byte[]");
        typeMap.put("blob", "Byte[]");
        // 其他类型的映射可以根据实际需求添加
    }

    public static String convert(String mySqlType) {
        return typeMap.getOrDefault(mySqlType.toLowerCase(), "String");
    }

    public static void main(String[] args) {
        String mySqlType = "varchar";
        String javaType = MySQLToJavaTypeUtil.convert(mySqlType);
        System.out.println("MySQL type [" + mySqlType + "] maps to Java type [" + javaType + "]");

        String unknownType = "customtype";
        String unknownJavaType = MySQLToJavaTypeUtil.convert(unknownType);
        System.out.println("Unknown MySQL type [" + unknownType + "] maps to Java type [" + unknownJavaType + "]");
    }
}
